package singleton;

/**
 * @Author: linKe
 * @Date: 2022/1/15 15:29
 * @FileName: S2
 * @version: 1.0
 * @Description: 第二种单例直接初始化
 */
public class S2 {
    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            System.out.println(S2.getInstance());
            /*
            singleton.S2@7f31245a
            singleton.S2@7f31245a
            singleton.S2@7f31245a
            singleton.S2@7f31245a
            singleton.S2@7f31245a
             */
        }
    }
    private static S2 s2 = new S2();

    private S2() {}

    public synchronized static S2 getInstance() {
        return s2;
    }

}
